var t = getApp();

Page({
  data: {
    arr: []
  },
  onLoad: function(options) {
    var that = this
    var zid = options.zid
    var u_id = options.u_id
    var id = options.id
    if (options.types) {
      that.setData({
        types: options.types
      })
    }
    t.util.request({
      'url': 'entry/wxapp/docuser.addfenzu',
      data: {
        zid: zid,
        op: 'display',
      },
      success: function(res) {
        console.log(res)
        that.setData({
          arr: res.data
        })
      }
    })
    that.setData({
      zid: zid,
      u_id: u_id,
      id: id
    })
  },
  click: function(a) {
    console.log(a)
    var that = this
    var fenzuid = a.currentTarget.dataset.fenzuid
    var zid = that.data.zid
    var u_id = that.data.u_id
    var id = that.data.id
    t.util.request({
      'url': 'entry/wxapp/docuser.ydfenzu',
      data: {
        u_id: u_id,
        zid: zid,
        fenzuid: fenzuid,
        id: id
      },
      success: function(res) {
        console.log(res)
        if (that.data.types == 2) {
          if (res.data == 1) {
            var pages = getCurrentPages();
            var prevPage = pages[pages.length - 2];
            prevPage.setData({
              type: 1
            })
            wx.showToast({
              title: "移动成功",
              icon: "none",
              duration: 1e3,
              success: function() {
                setTimeout(function() {
                  //要延时执行的代码
                  wx.navigateBack({
                    delta: 2
                  })
                }, 2000)
              }
            });

          }
        } else {
          if (res.data == 1) {
            var pages = getCurrentPages();
            var prevPage = pages[pages.length - 2];
            prevPage.setData({
              type: 1
            })
            wx.showToast({
              title: "移动成功",
              icon: "none",
              duration: 1e3,
              success: function() {
                setTimeout(function() {
                  //要延时执行的代码
                  wx.navigateBack({
                    delta: 1
                  })
                }, 2000)
              }
            });

          }
        }
      }
    })
  },
  onShow: function() {},
  onClock: function(a) {

  }
});